package com.atguigu.eduservice.controller.front;

import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RequestMapping("/eduservice/teacherfront")
@RestController
@CrossOrigin
public class TeacherFrontController {
    @Autowired
    private EduTeacherService teacherService;

    @Autowired
    private EduCourseService courseService;


    //分页查询讲师
    @PostMapping("getTeacherFrontList/{page}/{limit}")
    public R getTeacherFrontList(@PathVariable long page
    ,@PathVariable long limit){
        Page<EduTeacher> teacherPage=new Page<>(page,limit);
        Map<String,Object> map=teacherService.getTeacherFrontList(teacherPage);

        //返回分页所有数据
        return R.ok().data(map);
    }

    //讲师详情查询，即点击讲师头像，可以弹出他的履历
    @GetMapping("getTeacherFrontInfo/{teacherId}")
    public R getTeacherFrontInfo(@PathVariable String teacherId){
        //根据讲师id查询他的基本信息
        EduTeacher eduTeacher = teacherService.getById(teacherId);

        //根据讲师id查询他的授课信息
        QueryWrapper<EduCourse> wrapper=new QueryWrapper<>();
        wrapper.eq("teacher_id",teacherId);
        List<EduCourse> eduCourses = courseService.list(wrapper);

        return R.ok().data("teacher",eduTeacher).data("courseList",eduCourses);
    }

}
